package handler

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"three/api/request"
	"three/internal/dao"
	"three/internal/model"
)

func AddRoom(c *gin.Context) {
	var req request.AddRoom
	if err := c.ShouldBind(&req); err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 500,
			"msg":  "验证失败",
			"data": err.Error(),
		})
		return
	}
	room := model.Rooms{
		UserId: req.UserId,
		RoomId: req.RoomId,
	}
	if !dao.Create(&room) {
		c.JSON(http.StatusOK, gin.H{
			"code": 500,
			"msg":  "开启失败",
			"data": nil,
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code": 200,
		"msg":  "ok",
		"data": room,
	})
	return
}

func UpdateRoom(c *gin.Context) {
	var req request.UpdateRoom
	if err := c.ShouldBind(&req); err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 500,
			"msg":  "验证失败",
			"data": err.Error(),
		})
		return
	}
	room := model.Rooms{
		Id:     req.Id,
		Status: req.Status,
	}
	if !dao.Update(&room) {
		c.JSON(http.StatusOK, gin.H{
			"code": 500,
			"msg":  "修改失败",
			"data": nil,
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code": 200,
		"msg":  "ok",
		"data": room,
	})
	return
}
